package com.jeremyfeinstein.utils.NetUtils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * @author : lishan
 * @e-mail : cnlishan@163.com
 * @date : 2021/2/8 8:50 AM
 * @desc :
 */
public class SGApiService {
    public static final OkHttpClient okHttpClient;
    private static String sBaseUrl = "";
    public static Convert sConvert;

    static {
        okHttpClient = new OkHttpClient.Builder()
                .readTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .connectTimeout(10, TimeUnit.SECONDS)
                .build();
    }

    /**
     * 初始化
     *
     * @param baseUrl 请求基本地址
     * @param convert 转化工具
     */
    public static void init(String baseUrl, Convert convert) {
        sBaseUrl = baseUrl;
        if (convert == null) {
            convert = new SGJsonConvert();
        }
        sConvert = convert;
    }

    public static <T> PostJSONRequest<T> postJSON(String url) {
        if (!url.isEmpty() && url.contains("http")) {
            return new PostJSONRequest<>(url);
        }
        return new PostJSONRequest<>(sBaseUrl + url);
    }
}
